package com.dianmi.seckill.common.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * @author xieqiaofu
 * @date 2020/12/24
 */
public class NumberUtils {

    public static String formatMoney(Number number) {
        NumberFormat f = new DecimalFormat("#,###.####");
        return f.format(number);
    }

    public static void main(String[] args) {
        Integer count = 123456789;
        String s = NumberUtils.formatMoney(count);
        System.out.println(s);

        BigDecimal bigDecimal = new BigDecimal("123456789.1234564789");
        String s1 = NumberUtils.formatMoney(bigDecimal);
        System.out.println(s1);

        BigDecimal bigDecimal2 = new BigDecimal("123456789.1");
        String s2 = NumberUtils.formatMoney(bigDecimal2);
        System.out.println(s2);

        Long count2 = 123456798163454L;
        String s3 = NumberUtils.formatMoney(count2);
        System.out.println(s3);
    }
}
